Skip to content

feature: add error_test.go in pkg/utils#984

Open
CygnusMaximillian wants to merge 1 commit into
goharbor:mainfrom
CygnusMaximillian:test/error-test
Open

feature: add error_test.go in pkg/utils#984
CygnusMaximillian wants to merge 1 commit into
goharbor:mainfrom
CygnusMaximillian:test/error-test

Conversation

@CygnusMaximillian

Copy link
Copy Markdown

Description

This pull request introduces unit tests for the error parsing utilities located in pkg/utils/error.go (ParseHarborErrorCode and ParseHarborErrorMsg).

Robust error handling is critical for the CLI's user experience. These functions are responsible for translating raw HTTP errors and API payloads into human-readable messages. Ensuring they work correctly prevents the CLI from displaying confusing, opaque, or raw JSON errors to end-users. This PR adds an isolated suite of table-driven tests to verify these functions against various expected error formats without altering any existing application logic.

Type of Change

Please select the relevant type.

  • Bug fix
  • New feature
  • Refactor
  • Documentation update
  • Chore / maintenance

Changes

  • Added a new test file pkg/utils/error_test.go.
  • Implemented TestParseHarborErrorMsg to verify error extraction from nil errors, generic Go errors, and structured Harbor API payload errors.
  • Implemented TestParseHarborErrorCode to verify status code extraction from bracketed formats (e.g., [GET ...][404]) and status formats (e.g., (status 500)).

@codecov

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 9.34%. Comparing base (60ad0bd) to head (d640e6b).
⚠️ Report is 186 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##             main    #984      +/-   ##
=========================================
- Coverage   10.99%   9.34%   -1.65%     
=========================================
  Files         173     321     +148     
  Lines        8671   16081    +7410     
=========================================
+ Hits          953    1503     +550     
- Misses       7612   14444    +6832     
- Partials      106     134      +28     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: CygnusMaximillian <dprajjwal11@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature] Add unit test coverage for error parsing utilities (pkg/utils/error.go)

1 participant